package com.cn.shop.controller;

import com.cn.shop.entity.home.Notice;
import com.cn.shop.service.ManageService;
import com.cn.shop.utils.ResultBean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 后管
 *
 * @author suhao
 * @time 2018-03-17
 * @email suhao755@gmail.com
 */
@RestController
@RequestMapping("manage")
public class ManageController {
    private ManageService manageService;

    public ManageController(ManageService manageService) {
        this.manageService = manageService;
    }
    /*获取用户列表*/
    @GetMapping("/userList")
    public ResultBean<List> userList(){
        return new ResultBean(manageService.getUserList());
    }
    /*删除用户信息*/
    @PostMapping("/deleteUser")
    public ResultBean deleteUser(String cifSeq){
        return new ResultBean(manageService.deleteUser(cifSeq));
    }
    /*获取公告列表*/
    @GetMapping("/noticeList")
    public ResultBean<List> noticeList(){
        return new ResultBean(manageService.getNoticeList());
    }
    /*查看公告详情*/
    @GetMapping("/noticeDetail")
    public ResultBean<Map> noticeDetail(int noticeId){
        return new ResultBean(manageService.getNoticeDetail(noticeId));
    }
    /*删除公告*/
    @PostMapping("/deleteNotice")
    public ResultBean deleteNotice(int noticeId){
        return new ResultBean(manageService.deleteNotice(noticeId));
    }
    /*添加公告*/
    @PostMapping("/addNotice")
    public ResultBean addNotice(Notice notice){
        Map params = new HashMap();
        params.put("noticeId",notice.getNoticeId());
        params.put("noticeTitle",notice.getNoticeTitle());
        params.put("noticeTime",notice.getNoticeTime());
        params.put("noticeContent",notice.getNoticeContent());
        return new ResultBean(manageService.addNotice(params));
    }
    /*修改公告*/
    @PostMapping("/updateNotice")
    public ResultBean updateNotice(int noticeId, String noticeContent){
        return new ResultBean(manageService.updateNotice(noticeId,noticeContent));
    }
}
